CXX := g++
CC  := gcc

SUFFIX :=
EXE    := avplayer_ui

SOURCES := MediaPlayer.cpp CAVPlayer.cpp ./thirdparty/tlib/tlib.cpp
OBJS    := $(addsuffix .o, $(basename $(notdir $(SOURCES))))
UNAME_S := $(shell uname -s)
RES     := resource.res
VLC_SDK := ./

CFLAGS   :=
CXXFLAGS :=

# INCLUDE_PATHS specifies the additional include paths we'll need
INCLUDE_PATHS :=

# LIBRARY_PATHS specifies the additional library paths we'll need
LIBRARY_PATHS :=

# COMPILER_FLAGS specifies the additional compilation options we're using
# -w suppresses all warnings
# -Wl,-subsystem,windows gets rid of the console window
COMPILER_FLAGS := -g -Wall -Wformat -w -Wl,-subsystem,windows
COMPILER_FLAGS += -static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -lpthread -Wl,-Bdynamic

#LINKER_FLAGS specifies the libraries we're linking against
LINKER_FLAGS :=

##---------------------------------------------------------------------
## BUILD FLAGS PER PLATFORM
##---------------------------------------------------------------------

ifeq ($(OS), Windows_NT)
    ECHO_MESSAGE = "MinGW"

    LINKER_FLAGS += -lcomctl32 -lole32 -loleaut32 -mwindows
    LINKER_FLAGS += -L ${VLC_SDK} -lvlc -lvlccore

    INCLUDE_PATHS += -I./thirdparty/tlib -I..
    INCLUDE_PATHS += -Ivlc/include

    SUFFIX = .exe
endif


CFLAGS = $(CXXFLAGS)


EXE := $(EXE)$(SUFFIX)

##---------------------------------------------------------------------
## BUILD RULES
##---------------------------------------------------------------------

%.o:%.c
	$(CC) $(CFLAGS) $(INCLUDE_PATHS) $(COMPILER_FLAGS) -c -o $@ $<

%.o:%.cpp
	$(CXX) $(CXXFLAGS) $(INCLUDE_PATHS) $(COMPILER_FLAGS) -c -o $@ $<

%.o:./thirdparty/tlib/%.cpp
	$(CXX) $(CXXFLAGS) $(INCLUDE_PATHS) $(COMPILER_FLAGS) -c -o $@ $<


all: $(EXE)
	@echo Build complete for $(ECHO_MESSAGE)

$(EXE): $(OBJS) $(RES)
	$(CXX) -o $@ $^ $(CXXFLAGS) $(LIBRARY_PATHS) $(LINKER_FLAGS) $(RES)

$(RES): resource.rc
	windres -i $^ --input-format=rc -o $@ -O coff --use-temp-file

clean:
	rm -f $(EXE) $(OBJS) $(RES)
